﻿var Util = {
    event:function(events){
        var me = this,
            reg = /[^\s]+/g,
            matchs;
        $.each(events, function(k, v){
            matchs = k.match(reg);
            matchs.length == 2 ?
            $(matchs[0]).bind(matchs[1], function(e,fn){
                me[v].apply(me, [this, e]);
            }) :
            $(matchs[0]).delegate(matchs[1], matchs[2], function(e,fn){
                me[v].apply(me, [this, e,fn]);
            });
        });
    },
    isEmpty: function (){
        var len = arguments.length;
        if(len==0){ return true; }
        for(var i=0;i<len;i++){
            var a = arguments[i];
            if(typeof a === "undefined" || a == null || (typeof a === "string" && a.trim() == "")){
                return true;
            }else if(typeof a === "object"){
                var flg = true;
                for (var k in a ) {
                    flg=false;
                    break;
                }
                if(flg){ return true; }
            }
        }
        return false;
    }
};
Date.prototype.format = function(f){
    var o ={
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "H+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds() //millisecond
    };
    if(/(y+)/.test(f))f=f.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(f))f = f.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));return f
};
